package com.jyw.business.ast.domain.dto.web;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jyw.business.ast.constant.AstRelationConstant;
import com.jyw.business.ast.domain.AstDealRelation;
import com.jyw.business.ast.domain.AstTransfer;
import com.jyw.common.utils.DateUtils;
import com.jyw.common.utils.SecurityUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Data
@ApiModel("资产转移-转移申请-请求实体")
public class AstTransferDto {
    @ApiModelProperty("转出科室")
    @NotNull(message = "转出科室不能为空")
    private Long outDept;

    @ApiModelProperty("转移原因")
    private String reason;

    @ApiModelProperty("转移资产集合")
    private List<Long> astList;

    public AstTransfer buildTransfer(){
        AstTransfer transfer = new AstTransfer();
        transfer.setOutDept(getOutDept());
        transfer.setInDept(SecurityUtils.getDeptId());
        transfer.setReason(getReason());
        transfer.setAuditState("0");
        transfer.setCreateUser(SecurityUtils.getUserId());
        transfer.setCreateTime(DateUtils.getNowDate());
        return transfer;
    }

    /**
     * 构建关系表
     * @param transfer
     */
    public List<AstDealRelation> buildRelation(AstTransfer transfer) {
        return getAstList().stream().map(data -> {
            AstDealRelation relation = new AstDealRelation();
            relation.setType(AstRelationConstant.TRANSFER);
            relation.setBusinessId(transfer.getId());
            relation.setOutDept(getOutDept());
            relation.setInDept(transfer.getInDept());
            relation.setAstId(data);
            return relation;
        }).collect(Collectors.toList());
    }
}
